﻿using System.Globalization;
using System.Windows.Data;
using HelpDeskTool.Entities;
using HelpDeskTool.Extensions;

namespace HelpDeskTool.Converters;

public class StatusConverter : IValueConverter
{
	private readonly TimeSpan timeout = TimeSpan.FromSeconds(100);

	public object? Convert(object? value, Type targetType, object parameter, CultureInfo culture)
	{
		if (value is not WmiInfo wmiInfo)
			return null;

		var now = DateTime.Now;
		if (wmiInfo.Updated?.Add(timeout) > now)
			return $"онлайн ({(now - wmiInfo.LastBootUp)?.FormatRus()})";

		if (wmiInfo.Updated != null)
			return $"последний раз в сети: {wmiInfo.Updated:g}";

		return null;
	}

	public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
	{
		throw new NotImplementedException();
	}
}
